package moodle.android;

import net.patrickpollet.moodlews.core.CourseRecord;
import net.patrickpollet.moodlews.core.LoginReturn;
import net.patrickpollet.moodlews.core.Mdl_soapserverBindingStub;
import net.patrickpollet.moodlews.core.UserRecord;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;


public class ListaCursos extends Activity {
  	
	private ListView lista;
	Usuario user = new Usuario();
	Mdl_soapserverBindingStub moodle = user.getMoodle();//obtiene moodle			
	LoginReturn sesion = user.getSesion();//obtiene sesion
	CourseRecord[] arregloCursos;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);      
        setContentView(R.layout.list_course);
        
        this.arregloCursos = this.moodle.get_course(this.sesion.getClient(), this.sesion.getSessionkey(), "", "");//
        String[] cursos=new String[arregloCursos.length];
        for(int x=0;x!=arregloCursos.length;x++){
	    	   cursos[x]=arregloCursos[x].getFullname();	    	  
	    	  
	       }
  
        lista=(ListView) findViewById(R.id.listaCursos); 
        ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, cursos); 
        lista.setAdapter(adapter);//carga adaptador a la lista  
        
     	lista.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view, int posicion, long id) {
				Intent i = new Intent();
				i.putExtra("ID",arregloCursos[posicion].getId());
				i.setClass(getApplicationContext(),AlumnosCurso.class);	
				startActivity(i);
				// TODO Auto-generated method stub
				
			}
		
     	});
        
        }
	
	
	
  
       
}
	
